package cn.wlh.learn.webmagic.pipeline;

import cn.hutool.core.io.FileUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class PicPipeline extends AdapterDownLoadConversoinPipeline{
    private final static Log logger = LogFactory.get();

    private final String base;

    public PicPipeline(String base) {
        this("img","img",base);
    }
    public PicPipeline(String from, String to,String base) {
        super(from,to);
        this.base = base;
    }


    @Override
    protected Object downLoadStore(InputStream inputStream, String fileName) throws Exception {
        File file = null;
        File write = null;
        file = FileUtil.file(this.base, fileName);
        write = FileUtil.writeFromStream(inputStream, file);
        return write;
    }


}